package com.it.jzs.controller.admin;

import com.it.jzs.pojo.Link;
import com.it.jzs.pojo.Swiper;
import com.it.jzs.service.admin.AdminLinkService;
import com.it.jzs.service.admin.AdminSwiperService;
import com.it.jzs.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("admin")
@CrossOrigin
public class AdminSwiperController {

    @Resource
    private AdminSwiperService adminSwiperService;

    @GetMapping("swiper")
    public Result<Object> ListLinkPage(@RequestParam("index") Integer index, @RequestParam("size") Integer size) {  // 分页查询
//        System.out.println("page = " + index);
//        System.out.println("size = " + size);
        Result<Object> result = adminSwiperService.selectPage(index, size);
//        System.out.println("result = " + result);
        return result;
    }

    @PostMapping("swiper")
    public Result<Object> addSwiper(@RequestBody Swiper swiper) {  // 新增
//        System.out.println("type = " + type);
        Result<Object> result = adminSwiperService.insertOne(swiper);
//        return Result.success(null, "success");
        return result;
    }

    @DeleteMapping("swiper/{id}")
    public Result<Object> deleteSwiper(@PathVariable("id") Integer id) {  // 删除分类
        System.out.println("id = " + id);
        Result<Object> result = adminSwiperService.delete(id);
        return result;
//        return Result.success(null,"册数");
    }

    @PutMapping("swiper")
    public Result<Object> updateLink(@RequestBody Swiper swiper) {
//        System.out.println("type = " + type);
        Result<Object> result = adminSwiperService.update(swiper);
        return result;
    }
}
